package com.leanin.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.leanin.domain.RulesInfo;
import com.leanin.response.DataOutResponse;
import com.leanin.service.RulesInfoService;

@RestController
@RequestMapping("rules")
public class RulesInfoController {

	@Autowired
	private RulesInfoService rulesInfoService;
	
	@GetMapping("findCommonRules")
	public DataOutResponse findCommonRules(@RequestParam Integer rulesType,@RequestParam(required=false) String rulesName) {
		return rulesInfoService.findCommonRules(rulesType, rulesName);
	}
	
	@GetMapping("findRulesList")
	public DataOutResponse findRulesList(@RequestParam Integer page,@RequestParam Integer pageSize,@RequestParam(required=false) String rulesName,
										 @RequestParam Integer type,@RequestParam(required=false) Long typeId) {
		return rulesInfoService.findRulesList(page, pageSize, rulesName, type, typeId);	
	}
	
	@GetMapping("findRulesByWardCode")
	public DataOutResponse findRulesByWardCode(@RequestParam Integer page,@RequestParam Integer pageSize,@RequestParam String wardCode,
											   @RequestParam Integer rulesType,@RequestParam(required=false) String rulesName) {
		return rulesInfoService.findRulesByWardCode(page, pageSize, wardCode, rulesType, rulesName);
	}
	
	@GetMapping("updateRulesState")
	public DataOutResponse updateRulesState(@RequestParam Long rulesInfoId,@RequestParam Integer status) {
		return rulesInfoService.updateRulesState(rulesInfoId, status);
	}
	
	@PostMapping("addRulesInfo")
	public DataOutResponse addRulesInfo(@RequestBody RulesInfo record) {
		return rulesInfoService.addRulesInfo(record);
	}
	
	@PostMapping("updateRulesInfo")
	public DataOutResponse updateRulesInfo(@RequestBody RulesInfo record) {
		return rulesInfoService.updateRulesInfo(record);
	}
	
	@GetMapping("findRulesById")
	public DataOutResponse findRulesById(@RequestParam Long rulesInfoId) {
		return rulesInfoService.findRulesById(rulesInfoId);
	}
}
